package com.cskaoyan.controller.wxuser;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.MemoryBean;
import com.cskaoyan.bean.vo.wxuser.UserIndexInfo;
import com.cskaoyan.bean.vo.wxuser.UserIndexVo;
import com.cskaoyan.service.wxgoods.WxGoodsService;
import com.cskaoyan.service.wxuser.WxUserService;
import com.cskaoyan.util.common.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Ajun de BBC
 * @Date 2022/7/21 23:15
 * @Version 1.5
 */

@RequestMapping("wx/user")
@RestController
public class WxUserController {

    @Autowired
    MemoryBean memoryBean;
    @Autowired
    WxUserService wxUserService;


    //绑定
    private Integer getUserId(@RequestHeader(Constant.WX_TOKEN_HEADER) String token) {
        Integer userId = memoryBean.tokenAndUserId.get(token);
        if (userId == null) {
            return -1;
        }
        return userId;
    }

    @RequestMapping("index")
    public BaseRespVo userIndex(@RequestHeader(Constant.WX_TOKEN_HEADER) String token){
        Integer userId = getUserId(token);
        UserIndexVo order = wxUserService.userIndex(userId);
        return BaseRespVo.ok(order,"成功",0);
    }
}
